package cn.itcast.bos.consumer;

import java.util.List;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Component;

import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse.SmsSendDetailDTO;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;

import cn.itcast.bos.utils.SmsDemoUtils;

@Component("queueConsumer1")
public class SmsConsumer implements MessageListener {

	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage)message;
		try {
			String telephone = mapMessage.getString("telephone");
			String code = mapMessage.getString("code");
			//SendSmsResponse sendSms = SmsDemoUtils.sendSms(telephone, code);
			String smsCode = "OK";
			if(smsCode.equals("OK")){
				// QuerySendDetailsResponse querySendDetails = SmsDemoUtils.querySendDetails(sendSms.getBizId());
				// 发送成功
				System.out.println("发送短信成功,手机号："
						+ telephone + "，验证码："
						+ code );
//				List<SmsSendDetailDTO> smsSendDetailDTOs = querySendDetails.getSmsSendDetailDTOs();
//				for(QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO :smsSendDetailDTOs){
//					System.out.println("短信内容："+smsSendDetailDTO.getContent());
//				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
